
#include<stdio.h>
#define max 20010
int data[max][max];
int value[max];
void build(int a,int b,int c) {
	if (data[a][a] == 0) data[a][a] = 1;
	else data[a][a] = data[a][a]+ 1;
	data[a][b] = c;
	return;
}
struct edge{
	int a;
	int b;
	int c;
};
struct edge edg[max];
void shuchu(int n,int m) {
	
	int i;
	for (i = 0; i < n; i++) {
		if (data[m][i] == 0) continue;
		if(m==i) continue;
		printf("(%d,%d,%d)", m, i, data[m][i]);
	};
	return;

}
int main() {
	int n, e;
	scanf("%d%d", &n, &e);
	int i;
	for (i = 0; i < e; i++) {
		scanf("%d%d%d",&edg[i].a,&edg[i].b,&edg[i].c);
	};
	for(i=0;i<e;i++){
		build(edg[i].a,edg[i].b,edg[i].c);
	}
	int p;
	for (p = 0; p < n; p++) {
		if(data[p][p] == 0) continue;
		printf("%d:", p);
		shuchu(n, p);
		printf("\n");
	};
	return 0;

}
